﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Metropolitics.Source
{
    struct TextureStruct
    {
        public uint id; //unique to the tileset 
        public byte type; //tileset type
        public string name;
        public Texture2D texture;
    }

    public sealed class TextureLibrary
    {
        #region Members

        private static TextureLibrary instance = null;
        private static readonly object lockobject = new object();

        private List<TextureStruct> texturelist; 

        #endregion

        #region Properties

        #endregion

        #region Functions

        private TextureLibrary()
        {
        }

        public static TextureLibrary GetInstance()
        {
            lock(lockobject)
            {
                if(instance == null)
                {
                    instance = new TextureLibrary();
                }
                return instance;
            }
        }

        public void LoadDefaultTextures()
        {

        }

        public TextureStruct GetTexture(byte _type, int _id)
        {
            for (int i = 0; i < texturelist.Count; ++i)
            {
                if (texturelist[i].type == _type && texturelist[i].id == _id)
                {
                    return texturelist[i];
                }
            }

            return new TextureStruct();
        }

        public void CreateTexturesFromFile(ref City _city, string _filename)
        {
            //creating texture from the tile file
            
        }

        public void SaveTexture(Texture2D _texture, string _filename)
        {
        }

        #endregion
    }
}
